#ifndef APPADAPTERCONTROLLER_H
#define APPADAPTERCONTROLLER_H

#include <QMainWindow>
#include <QStackedWidget>
#include <QQueue>
#include <QStack>
#include "QScreen"
#include "3rdparty/tinyxml2-master/tinyxml2.h"

// 不同界面
#include "automatic/automatic_mode.h"
#include "manual_manipulation/manual_manipulation.h"
#include "zero_return_mode/zero_return_mode.h"
#include "user_switch/user_switch.h"
#include "menu/menu.h"
#include "util/util.h"
#include "thread/mythread.h"
#include "system_setting/system_setting.h"
#include "external_memory/external_memory.h"
#include "caltimer/caltimer.h"
#include "teachmode/teachmode.h"
#include "program_editor/program_editor.h"
#include "transmit_data/transmit_data.h"
#include "tcp_thread/tcp_thread.h"
#include "rs422_serial_port/rs422_serial_port.h"
#include "speed_add_dec/speed_add_dec.h"

class AppAdapterController : public QMainWindow
{
    Q_OBJECT


public:
    AppAdapterController(QWidget *parent = 0);
    ~AppAdapterController();

private:

    QStackedWidget *stackedWidget;
    ManualManipulation *manualManipulation;
    ZeroReturnMode *zeroReturnMode;
    AutomaticMode *automaticMode;
    Menu *menu;
    MyThread thread;
    UserSwitch *userSwitch;
    SystemSetting *systemSetting;
    ExternalMemory *externalMemory;
    CalTimer *calTimer;
    TeachMode *teachMode;
    ProgramEditor *programEditor;
    TransmitData *transmitData;
    tcp_thread *tcp_communication_thread;
    rs422_serial_port *rs422SerialPort;
    QStack<QDialog*> newAlarm_stack;
    speed_add_dec *speedAddDec;

    void createMenu();
    void createZeroReturnMode();
    void createManualManipulation();
    void createAutomaticMode();
    void createUserSwitch();
    void createSystemSetting();
    void createExternalMemory();
    void createCalTimer();
    void createTeachMode();
    void createProgramEditor();
    void createRS422Communication();
    void createSpeedAddDec();
    void connectModeSignals(QObject* mode);
    void isFileExist();
    void createTcpThread(QHostAddress ip, QString port);
    void TCP_msg_xml(const char* xmlPath);
    void detectAlarmState();
    void buildAutoProgram();

signals:
    void NewAlarmcreated(QString alarmName, int alarmNum, bool ifDisplayNewAlarm);

private slots:
    void go2ReturnZero();
    void go2Manual();
    void go2Automatic();
    void go2UserSwitch();
    void go2SystemSetting();
    void go2ExternalMemory();
    void go2CalTimer();
    void go2TeachMode();
    void go2ProgramEditor(const QString &buttonName = "aa");
    void go2RS422Communication();
    void go2SpeedAddDec();
    void returnMenu();
    void addSpeedValue();
    void decSpeedValue();
    void TcpCommunicationFlipped(bool ifTcpGoOn);
    void abortTcpConnect();
    void sendParamValue_TCP(const QString &MsgSentType, const QString &ParamName, const QString &ParamAttribute);
    void sendParamValue_TCP(const QString &ProgramName);
    void stopTcpConnect();
    void createNewAlarm(QString alarmName, int alarmNum, bool ifDisplayNewAlarm);
    void closeAlarmWidget();
    void parseFromProgramXml2TcpXml(XMLElement* ele_ProgramXml, XMLDocument* doc_TcpXml, XMLElement* ele_TcpXml);
    void setAxisMove(XMLDocument* doc, XMLElement* ele, const QString& axis_name,
                                           const QString &PosData, const QString &VelData);
};

#endif // APPADAPTERCONTROLLER_H
